//
//  TitleButton.swift
//  weibo
//
//  Created by hm on 2020/4/26.
//  Copyright © 2020 hm. All rights reserved.
//

import UIKit

class TitleButton: UIButton {

    override init(frame: CGRect) {
        super.init(frame: frame)
        //设置选中/为选中图标
        setImage(UIImage(named: "navigationbar_arrow_down"), for: .normal)
        setImage(UIImage(named: "navigationbar_arrow_up"), for: .selected)
        setTitleColor(UIColor.black, for: .normal)
        sizeToFit()
    }
    
    //重写控件的init方法，必须重写init?(coder: NSCoder)
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        //UIButton默认图标在左，文字在右
        // 交换label和image的位置
        // 让lable在左,image在右
        titleLabel!.frame.origin.x = 0
        imageView!.frame.origin.x = titleLabel!.frame.width + 5
    }
    
}
